namespace csharp
{
    class HanoiTower
    {
        public HanoiTower()
        {
        }

        public System.Collections.Generic.IEnumerable<string>
        move(int step, char from, char middle, char to)
        {
            if (step == 1)
            {
                yield return "将" + step + "从" + from + "复制到" + to;
            }
            else
            {
                // 迭代每一次压栈上层环的移动到中间柱的动作
                foreach (var msg in move(step - 1, from, to, middle))
                {
                    yield return msg;
                }
                System.Console.Write("\t[按回车键继续]\r\n");
                System.Console.ReadLine();

                // 迭代每一次压栈本环的移动到目标柱的动作
                yield return "将" + step + "从" + from + "复制到" + to;

                System.Console.Write("\t[按回车键继续]\r\n");
                System.Console.ReadLine();

                // 迭代每一次压栈上层环的移动到目标柱的动作
                foreach (var msg in move(step - 1, middle, from, to))
                {
                    yield return msg;
                }
            }
        }
    }
}
